/**
 * 
 */
package com.xbang.attendance.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.xbang.attendance.entity.order.DeliveryOrder;
import com.xbang.attendance.entity.order.PurchaseOrder;
import com.xbang.attendance.entity.order.StockOutLog;
import com.xbang.attendance.entity.product.Product;
import com.xbang.attendance.entity.stock.Inventory;
import com.xbang.attendance.entity.stock.InventoryExchange;
import com.xbang.attendance.entity.stock.InventoryRecord;
import com.xbang.attendance.entity.system.Warehouse;
import com.xbang.attendance.entity.system.WarehouseProductAgreement;
import com.xbang.core.service.BaseService;

import enumeration.InventoryOperation;

/**
 * @author dev.zhang
 * 
 *         库存信息service
 */
public interface InventoryService extends BaseService {

	/**
	 * 拿到某个仓库的存库信息
	 * 
	 * @param warehouse
	 *            仓库
	 * @return
	 * @throws Exception
	 */
	List<Inventory> getInventoryByWarehouse(Warehouse warehouse) throws Exception;

	/***
	 * 得到备用仓库关联的库存
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	List<Inventory> getInventoryByWarehouseId(Integer id) throws Exception;

	/***
	 *验证该仓库是否存在库存
	 * 
	 * @param warehouse
	 * @return
	 * @throws Exception
	 */
	Boolean warehouseIsExist(Warehouse warehouse) throws Exception;

	/**
	 * 查找库存
	 * 
	 * @param warehouse
	 *            仓库
	 * @param product
	 *            产品
	 * @return
	 * @throws Exception
	 */
	Inventory getInventoryByParameters(Warehouse warehouse, Product product) throws Exception;
	
	/**
	 * 拿到仓储调货实体
	 * 
	 * @param id
	 *            key
	 * @return
	 * @throws Exception
	 */
	InventoryExchange getInventoryExchangeByKey(Integer id) throws Exception;

	/**
	 * 拿到仓储记录实体
	 * 
	 * @param id
	 *            key
	 * @return
	 * @throws Exception
	 */
	InventoryRecord getInventoryRecordByKey(Integer id) throws Exception;

	/***
	 * 拿到仓库实体
	 * 
	 * @param product
	 *            产品
	 * @return
	 */
	Inventory getInventoryByProduct(Product product) throws Exception;

	/**
	 * 根据仓储和产品拿到出入库记录
	 * 
	 * @param warehouse
	 *            仓储
	 * @param product
	 *            产品
	 * @param inventoryOperation
	 *            出入库类型
	 * @param exactMatch
	 *            是否已经补货
	 * @return
	 * @throws Exception
	 */
	List<InventoryRecord> searchInventoryRecords(Warehouse warehouse, Product product, InventoryOperation inventoryOperation, boolean exactMatch)
			throws Exception;

	/**
	 * 根据仓储和产品拿到出入库记录,默认拿没有完全补货的
	 * 
	 * @param warehouse
	 *            仓储
	 * @param product
	 *            产品
	 * @param inventoryOperation
	 *            出库类型
	 * @return
	 * @throws Exception
	 */
	List<InventoryRecord> searchInventoryRecords(Warehouse warehouse, Product product, InventoryOperation inventoryOperation) throws Exception;

	/**
	 * 根据仓储和产品拿到出入库记录,默认拿没有完全补货的，并且是出库
	 * 
	 * @param warehouse
	 *            仓储
	 * @param product
	 *            产品
	 * @return
	 * @throws Exception
	 */
	List<InventoryRecord> searchInventoryRecords(Warehouse warehouse, Product product) throws Exception;

	/**
	 * 更新和插入出入库记录----补货
	 * 
	 * @param warehouse
	 *            仓库
	 * @param product
	 *            产品
	 * @param inventory
	 *            库存
	 * @param soNumber
	 *            sales order number
	 * @param soDate
	 *            sales date
	 * @param amount
	 *            入库数量
	 * @throws Exception
	 */
	void updateInventoryRecordByReplenishment(Warehouse warehouse, Product product, Inventory inventory, String soNumber, Date soDate, BigDecimal amount)
			throws Exception;

	/**
	 * 跟新库存信息中的预警信息
	 * 
	 * @param warningInventorys
	 * @throws Exception
	 */
	void updateInventoryWarning(Set<Inventory> warningInventorys) throws Exception;

	/**
	 * 跟新产品约定数量、跟新产品调货信息
	 * 
	 * @param inventory
	 * @throws Exception
	 */
	void updateInventoryExchangeAgreementAmount(Inventory inventory) throws Exception;

	/**
	 * 跟新库存的预警
	 * 
	 * @param inventory
	 * @throws Exception
	 */
	void updateInventoryWarning(Inventory inventory) throws Exception;

	/**
	 * 根据库存拿到最近的补货记录
	 * 
	 * @param inventory
	 *            库存
	 * @return
	 * @throws Exception
	 */
	InventoryRecord getRecentReplenishmentRecord(Inventory inventory) throws Exception;

	/**
	 * 根据仓储和产品拿到最近的补货记录
	 * 
	 * @param warehouse
	 *            仓储
	 * @param product
	 *            产品
	 * @return
	 * @throws Exception
	 */
	InventoryRecord getRecentReplenishmentRecord(Warehouse warehouse, Product product) throws Exception;

	/**
	 * 拿到某个日期之前的出库、调出记录
	 * 
	 * @param warehouse
	 *            仓储
	 * @param product
	 *            产品
	 * @param date
	 *            日期
	 * @return
	 * @throws Exception
	 */
	List<InventoryRecord> getBeforTimeInventoryRecord(Warehouse warehouse, Product product, Date date) throws Exception;

	/**
	 * 拿到仓储产品的约定数量
	 * 
	 * @param warehouse
	 * @param product
	 * @return
	 * @throws Exception
	 */
	WarehouseProductAgreement getWarehouseProductAgreementByParameter(Warehouse warehouse, Product product) throws Exception;

	/**
	 * 得到时间片段
	 * 
	 * @return
	 * @throws Exception
	 */
	List<String> getInventoryRecordTimePart() throws Exception;

	/**
	 * 得到时间片段
	 * 
	 * @param warehouse
	 *            仓库
	 * @return
	 * @throws Exception
	 */
	List<String> getInventoryRecordTimePart(Warehouse warehouse) throws Exception;
	
	/***
	 * 根据PO找到它的出库记录
	 * @param order
	 * @return
	 */
	List<InventoryRecord> getInventoryRecordsByPurchaseOrder(PurchaseOrder order);
	/***
	 * 根据PID号码，查找它 的出库记录，看看是否已经补货
	 * @param pid
	 * @return
	 * @throws Exception
	 */
	Boolean isAddProduct(Integer pid)throws Exception;
	/**
	 * 跟据出库记录，对仓储进行补货
	 * @param inventoryRecords
	 * @throws Exception
	 */
	void addProduct(List<InventoryRecord> inventoryRecords,String soNumber)throws Exception;
	/***
	 * 到处实时库存
	 * @param webPath
	 * @param type
	 * @return
	 * @throws Exception
	 */
	 String genericExcelFile(String webPath,String type) throws Exception; 
	 
	 /***
	  * 缺货记录
	  * @param po
	  * @param pro
	  * @return
	  * @throws Exception
	  */
	 StockOutLog getLog(PurchaseOrder po,Product pro)throws Exception;
	 
	 /***
		 * 到处实时库存
		 * @param webPath
		 * @param type
		 * @return
		 * @throws Exception
		 */
	 String genericExcelFile(String webPath,Date beginDate,Date endDate) throws Exception; 
}